﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Hubble.SQLClient;

namespace CSP.DataAccess
{
    public class HBHelper
    {
        private HBHelper()
        { 
        
        }

        /// <summary>
        /// 根据字符串连接，Hubble的select语句,缓存时间，获取相应数据
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="commandText"></param>
        /// <param name="cacheTimeOut"></param>
        /// <returns></returns>
        public static DataSet ExecuteDataset(string connectionString, string commandText,int cacheTimeOut=0)
        {
            DataSet ds = new DataSet();
            using (HubbleAsyncConnection conn = new HubbleAsyncConnection(connectionString))
            {
                //打开连接
                conn.Open();
                

                //实例化Hubble适配器
                HubbleDataAdapter adapter = new HubbleDataAdapter();

                adapter.SelectCommand = new HubbleCommand(commandText, conn);
                //设置缓存过期时间
                adapter.SelectCommand.CacheTimeout = cacheTimeOut;

                //建立Command命令
                HubbleCommand matchCmd=adapter.SelectCommand;
                ds = matchCmd.Query(cacheTimeOut);
            }

            return ds;
        }


    }
}
